package com.pureut.quality.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.quality.domain.dto.QualityInspectionManagementDto;
import com.pureut.quality.domain.dto.QualitySchemeConfigurationDto;
import com.pureut.quality.domain.vo.InspectionMarkVo;
import com.pureut.quality.domain.vo.OrderReviewVo;
import com.pureut.quality.domain.vo.QualityInspectionManagementVo;
import com.pureut.quality.domain.vo.QualitySchemeConfigurationVo;
import com.pureut.quality.service.QualityInspectionManagementService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

/***
 * 免检管理控制层
 * Author:C
 * Date:2023/02/03 13:56
 * @DESC
 */
@RestController
@RequestMapping("/quality-inspection-management")
public class QualityInspectionManagementController extends BaseController {

    @Resource
    QualityInspectionManagementService qualityInspectionManagementService;

    /**
     * 免检管理列表
     */
    @RequiresPermissions("quality:verifyconfig:freeinspect:list")
    @GetMapping("/list")
    public TableDataInfo getList(QualityInspectionManagementVo qualityInspectionManagementVo) {
        startPage();
        //查询检验方案配置列表
        List<QualityInspectionManagementDto> list = qualityInspectionManagementService.getManagementList(qualityInspectionManagementVo);
        return getDataTable(list);
    }

    /**
     * 免检管理新增
     */
    @RequiresPermissions("quality:verifyconfig:freeinspect:add")
    @PostMapping("/add")
    @Log(title = "免检管理新增", businessType = BusinessType.INSERT)
    public AjaxResult add(@Validated @RequestBody QualityInspectionManagementVo qualityInspectionManagementVo) throws Exception {
        return toAjax(qualityInspectionManagementService.add(qualityInspectionManagementVo));
    }

    /**
     * 免检管理查看
     */
    @RequiresPermissions("quality:verifyconfig:freeinspect:query")
    @GetMapping("/view/{id}")
    public AjaxResult add(@PathVariable("id") Long id) {
        return AjaxResult.success(qualityInspectionManagementService.getViewById(id));
    }

    /**
     * 免检管理修改
     */
    @RequiresPermissions("quality:verifyconfig:freeinspect:edit")
    @PutMapping("/update")
    @Log(title = "免检管理修改", businessType = BusinessType.UPDATE)
    public AjaxResult update(@Validated @RequestBody QualityInspectionManagementVo qualityInspectionManagementVo) {
        return toAjax(qualityInspectionManagementService.updateManagement(qualityInspectionManagementVo));
    }

    /**
     * 删除
     */
    @RequiresPermissions("quality:verifyconfig:freeinspect:remove")
    @DeleteMapping("/delete/{idStr}")
    @Log(title = "免检管理删除", businessType = BusinessType.DELETE)
    public AjaxResult delete(@PathVariable("idStr") String idStr) {
        return toAjax(qualityInspectionManagementService.delete(idStr));
    }

    /**
     * 审核
     */
    @RequiresPermissions("quality:verifyconfig:freeinspect:examine")
    @Log(title = "免检管理审核", businessType = BusinessType.UPDATE)
    @PostMapping("/managementReview")
    public AjaxResult managementReview(@Validated @RequestBody OrderReviewVo orderReviewVo) throws ParseException {
        return toAjax(qualityInspectionManagementService.managementReview(orderReviewVo));
    }

    /**
     * 终止
     */
    @RequiresPermissions("quality:verifyconfig:freeinspect:over")
    @GetMapping("/stop/{idStr}")
    @Log(title = "免检管理终止", businessType = BusinessType.UPDATE)
    public AjaxResult stop(@PathVariable("idStr") String idStr) {
        return toAjax(qualityInspectionManagementService.stop(idStr));
    }

    /**
     * 根据供应商加物料编码/加工商加物料编码获取物料免检状态（feign调用）
     */
    @PostMapping("/getInspectionMark")
    public AjaxResult getInspectionMark(@RequestBody InspectionMarkVo inspectionMarkVo) {
        return AjaxResult.success(qualityInspectionManagementService.getInspectionMark(inspectionMarkVo));
    }
}
